package com.flask.colorpicker.cameralibrary.util;

import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * log util
 */
public class LogUtil {
    /**
     * log default tag
     */
    public static final String DEFAULT_TAG = "CameraView";

    private static final int WATCH_DOMAIN = 0xD003A01;

    private static final String SEPARATE_SYMBOL = ":";

    private static final String VERSION_CODE = "100001";

    private static final String SEPARATE_SLASH_SYMBOL = "/";

    private static final String TAG_LOG = DEFAULT_TAG + SEPARATE_SLASH_SYMBOL + VERSION_CODE;

    private static final int LOG_TYPE = 3;

    private static final HiLogLabel LABEL_LOG = new HiLogLabel(LOG_TYPE, WATCH_DOMAIN, LogUtil.TAG_LOG);

    private static String sCombinedMsg;

    private LogUtil() {
    }

    /**
     * debug级别日志打印方法
     *
     * @param tag    日志打印类标签
     * @param format 标准格式化参数
     */
    public static void debug(String tag, String format) {
        if (HiLog.isLoggable(WATCH_DOMAIN, tag, HiLog.INFO)) {
            if (isEmpty(tag)) {
                sCombinedMsg = tag + SEPARATE_SYMBOL + format;
                HiLog.debug(LABEL_LOG, sCombinedMsg);
            }
        }
    }

    /**
     * info级别日志打印方法
     *
     * @param tag    日志打印类标签
     * @param format 标准格式化参数
     */
    public static  void info(String tag, String format) {
        if (HiLog.isLoggable(WATCH_DOMAIN, tag, HiLog.INFO)) {
            if (isEmpty(tag)) {
                sCombinedMsg = tag + SEPARATE_SYMBOL + format;
                HiLog.info(LABEL_LOG, sCombinedMsg);
            }
        }
    }

    /**
     * error级别日志打印方法
     *
     * @param tag    日志打印类标签
     * @param format 标准格式化参数
     */
    public static void error(String tag, String format) {
        if (HiLog.isLoggable(WATCH_DOMAIN, tag, HiLog.INFO)) {
            if (isEmpty(tag)) {
                sCombinedMsg = tag + SEPARATE_SYMBOL + format;
                HiLog.error(LABEL_LOG, sCombinedMsg);
            }
        }
    }

    /**
     * fatal级别日志打印方法
     *
     * @param tag    日志打印类标签
     * @param format 标准格式化参数
     */
    public static void fatal(String tag, String format) {
        if (HiLog.isLoggable(WATCH_DOMAIN, tag, HiLog.INFO)) {
            if (isEmpty(tag)) {
                sCombinedMsg = tag + SEPARATE_SYMBOL + format;
                HiLog.fatal(LABEL_LOG, sCombinedMsg);
            }
        }
    }

    private static boolean isEmpty(CharSequence str) {
        return str != null && str.length() != 0;
    }
}
